USE [usuarios]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_tbl_perfil_aplicacion_tbl_aplicacion]') AND parent_object_id = OBJECT_ID(N'[dbo].[tbl_perfil_aplicacion]'))
ALTER TABLE [dbo].[tbl_perfil_aplicacion] DROP CONSTRAINT [FK_tbl_perfil_aplicacion_tbl_aplicacion]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_tbl_perfil_aplicacion_tbl_perfil]') AND parent_object_id = OBJECT_ID(N'[dbo].[tbl_perfil_aplicacion]'))
ALTER TABLE [dbo].[tbl_perfil_aplicacion] DROP CONSTRAINT [FK_tbl_perfil_aplicacion_tbl_perfil]
GO

USE [usuarios]
GO

/****** Object:  Table [dbo].[tbl_perfil_aplicacion]    Script Date: 06/29/2011 09:15:10 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tbl_perfil_aplicacion]') AND type in (N'U'))
DROP TABLE [dbo].[tbl_perfil_aplicacion]
GO

USE [usuarios]
GO

/****** Object:  Table [dbo].[tbl_perfil_aplicacion]    Script Date: 06/29/2011 09:15:10 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[tbl_perfil_aplicacion](
	[ape_per_id] [varchar](10) NOT NULL,
	[ape_apl_id] [varchar](10) NOT NULL,
	[ape_permiso] [bigint] NOT NULL,
 CONSTRAINT [PK_tbl_perfil_aplicacion] PRIMARY KEY CLUSTERED 
(
	[ape_per_id] ASC,
	[ape_apl_id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[tbl_perfil_aplicacion]  WITH CHECK ADD  CONSTRAINT [FK_tbl_perfil_aplicacion_tbl_aplicacion] FOREIGN KEY([ape_apl_id])
REFERENCES [dbo].[tbl_aplicacion] ([apl_id])
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[tbl_perfil_aplicacion] CHECK CONSTRAINT [FK_tbl_perfil_aplicacion_tbl_aplicacion]
GO

ALTER TABLE [dbo].[tbl_perfil_aplicacion]  WITH CHECK ADD  CONSTRAINT [FK_tbl_perfil_aplicacion_tbl_perfil] FOREIGN KEY([ape_per_id])
REFERENCES [dbo].[tbl_perfil] ([per_id])
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[tbl_perfil_aplicacion] CHECK CONSTRAINT [FK_tbl_perfil_aplicacion_tbl_perfil]
GO

